﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Collections;
using Newtonsoft.Json.Linq;

namespace SysSU.UbiBroker
{
    public class Tuple
    {
        internal IDictionary<string, object> Fields { get; private set; }

        public Tuple()
        {
            Fields = new Dictionary<string, object>();
        }

        public Tuple(JToken jsonObject)
        {
            
        }

        public Tuple AddField(string name, object value)
        {
            if (value is bool 
                || value is byte || value is sbyte
                || value is short || value is ushort
                || value is int || value is uint
                || value is long || value is ulong
                || value is float || value is double
                || value is string || value is IList || value is Tuple)
            {
                Fields[name] = value;
                return this;
            }
            else
            {
                throw new ArgumentException(
                    "Invalid value type. Only Boolean, Number, String, IList<object> and Tuple are accepted");
            }
        }

        public Tuple RemoveField(string name)
        {
            if (Fields.ContainsKey(name))
            {
                Fields.Remove(name);
            }
            return this;
        }
    }
}
